import Category from "../src/Category";

const uniformedCategories = [
{code:"0000",name:"未识别科目",desc:"",type:"无", style: 'warn'},
{code:"1000",name:"货币资金",desc:"",type:"资产类", upperCate:'货币资金'},
{code:"1001",name:"库存现金",desc:"",type:"资产类", upperCate:'货币资金'},
{code:"1002",name:"银行存款",desc:"",type:"资产类", upperCate:'货币资金'},
{code:"1003",name:"存放中央银行款项",desc:"银行专用",type:"资产类", upperCate:'货币资金'},
{code:"1011",name:"存放同业",desc:"银行专用",type:"资产类"},
{code:"1015",name:"其他货币资金",desc:"",type:"资产类"},
{code:"1021",name:"结算备付金",desc:"证券专用",type:"资产类"},
{code:"1031",name:"存出保证金",desc:"金融共用",type:"资产类"},
{code:"1051",name:"拆出资金",desc:"金融共用",type:"资产类"},
{code:"1101",name:"交易性金融资产",desc:"",type:"资产类"},
{code:"1111",name:"买入返售金融资产",desc:"金融共用",type:"资产类"},
{code:"1121",name:"应收票据",desc:"",type:"资产类"},
{code:"1122",name:"应收账款",desc:"",type:"资产类"},
{code:"1123",name:"预付账款",desc:"",type:"资产类"},
{code:"1131",name:"应收股利",desc:"",type:"资产类"},
{code:"1132",name:"应收利息",desc:"",type:"资产类"},
{code:"1211",name:"应收保护储金",desc:"保险专用",type:"资产类"},
{code:"1221",name:"应收代位追偿款",desc:"保险专用",type:"资产类"},
{code:"1222",name:"应收分保账款",desc:"保险专用",type:"资产类"},
{code:"1223",name:"应收分保未到期责任准备",desc:"保险专用",type:"资产类"},
{code:"1224",name:"应收分保保险责任准备金",desc:"保险专用",type:"资产类"},
{code:"1231",name:"其他应收款",desc:"",type:"资产类"},
{code:"1241",name:"坏账准备",desc:"",type:"资产类"},
{code:"1251",name:"贴现资产",desc:"银行专用",type:"资产类"},
{code:"1301",name:"贷款",desc:"",type:"资产类"},
{code:"1302",name:"贷款损失准备",desc:"银行和保险共用",type:"资产类"},
{code:"1311",name:"代理兑付证券",desc:"银行和保险共用",type:"资产类"},
{code:"1321",name:"代理业务资产",desc:"",type:"资产类"},
{code:"1401",name:"材料采购",desc:"",type:"资产类", upperCate: '存货'},
{code:"1402",name:"在途物资",desc:"",type:"资产类", upperCate: '存货'},
{code:"1403",name:"存货",desc:"",type:"资产类", upperCate: '存货'},
{code:"1404",name:"原材料",desc:"",type:"资产类", upperCate: '存货'},
{code:"1405",name:"材料成本差异",desc:"",type:"资产类", upperCate: '存货'},
{code:"1406",name:"库存商品",desc:"",type:"资产类", upperCate: '存货'},
{code:"1407",name:"发出商品",desc:"",type:"资产类", upperCate: '存货'},
{code:"1410",name:"商品进销差价",desc:"",type:"资产类", upperCate: '存货'},
{code:"1411",name:"委托加工物资",desc:"",type:"资产类", upperCate: '存货'},
{code:"1412",name:"包装物及低值易耗品",desc:"",type:"资产类", upperCate: '存货'},
{code:"1421",name:"消耗性物物资产",desc:"农业专用",type:"资产类", upperCate: '存货'},
{code:"1431",name:"周转材料",desc:"建造承包商专用",type:"资产类", upperCate: '存货'},
{code:"1441",name:"贵金属",desc:"银行专用",type:"资产类", upperCate: '存货'},
{code:"1442",name:"抵债资产",desc:"金融共用",type:"资产类", upperCate: '存货'},
{code:"1451",name:"损余物资",desc:"保险专用",type:"资产类", upperCate: '存货'},
{code:"1461",name:"存货跌价准备",desc:"",type:"资产类", upperCate: '存货'},
{code:"1501",name:"待摊费用",desc:"",type:"资产类"},
{code:"1511",name:"独立账户资产",desc:"保险专用",type:"资产类"},
{code:"1521",name:"持有至到期投资",desc:"",type:"资产类"},
{code:"1522",name:"持有至到期投资减值准备",desc:"",type:"资产类"},
{code:"1523",name:"可供出售金融资产",desc:"",type:"资产类"},
{code:"1524",name:"长期股权投资",desc:"",type:"资产类"},
{code:"1525",name:"长期股权投资减值准备",desc:"",type:"资产类"},
{code:"1526",name:"投资性房地产",desc:"",type:"资产类"},
{code:"1531",name:"长期应收款",desc:"",type:"资产类"},
{code:"1541",name:"未实现融资收益",desc:"",type:"资产类"},
{code:"1551",name:"存出资本保证金",desc:"保险专用",type:"资产类"},
{code:"1602",name:"累计折旧",desc:"",type:"资产类"},
{code:"1603",name:"固定资产减值准备",desc:"",type:"资产类"},
{code:"1601",name:"固定资产",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1604",name:"在建工程",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1605",name:"工程物资",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1606",name:"固定资产清理",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1611",name:"融资租赁资产",desc:"租赁专用",type:"资产类", upperCate: '固定资产'},
{code:"1612",name:"未担保余值",desc:"租赁专用",type:"资产类", upperCate: '固定资产'},
{code:"1621",name:"生产性生物资产",desc:"农业专用",type:"资产类", upperCate: '固定资产'},
{code:"1622",name:"生产性生物资产累计折旧",desc:"农业专用",type:"资产类", upperCate: '固定资产'},
{code:"1623",name:"公益性生物资产",desc:"农业专用",type:"资产类", upperCate: '固定资产'},
{code:"1631",name:"油气资产",desc:"石油天然气开采专用",type:"资产类", upperCate: '固定资产'},
{code:"1632",name:"累计折耗",desc:"石油天然气开采专用",type:"资产类", upperCate: '固定资产'},
{code:"1701",name:"无形资产",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1702",name:"累计摊销",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1703",name:"无形资产减值准备",desc:"",type:"资产类", upperCate: '固定资产'},
{code:"1711",name:"商誉",desc:"",type:"资产类"},
{code:"1801",name:"长期待摊费用",desc:"",type:"资产类"},
{code:"1811",name:"递延所得资产",desc:"",type:"资产类"},
{code:"1901",name:"待处理财产损益",desc:"",type:"资产类"},
{code:"2001",name:"短期借款",desc:"",type:"负债类"},
{code:"2002",name:"存入保证金",desc:"金融共用",type:"负债类"},
{code:"2003",name:"拆入资金",desc:"金融共用",type:"负债类"},
{code:"2004",name:"向中央银行借款",desc:"银行专用",type:"负债类"},
{code:"2011",name:"同业存放",desc:"银行专用",type:"负债类"},
{code:"2012",name:"吸收存款",desc:"银行专用",type:"负债类"},
{code:"2021",name:"贴现负债",desc:"银行专用",type:"负债类"},
{code:"2101",name:"交易性金融负债",desc:"",type:"负债类"},
{code:"2111",name:"专出回购金融资产款",desc:"金融共用",type:"负债类"},
{code:"2201",name:"应付票据",desc:"",type:"负债类"},
{code:"2202",name:"应付账款",desc:"",type:"负债类"},
{code:"2205",name:"预收账款",desc:"",type:"负债类"},
{code:"2211",name:"应付职工薪酬",desc:"",type:"负债类"},
{code:"2221",name:"应交税费",desc:"",type:"负债类"},
{code:"2231",name:"应付股利",desc:"",type:"负债类"},
{code:"2232",name:"应付利息",desc:"",type:"负债类"},
{code:"2241",name:"其他应付款",desc:"",type:"负债类"},
{code:"2251",name:"应付保户红利",desc:"保险专用",type:"负债类"},
{code:"2261",name:"应付分保账款",desc:"保险专用",type:"负债类"},
{code:"2311",name:"代理买卖证券款",desc:"证券专用",type:"负债类"},
{code:"2312",name:"代理承销证券款",desc:"证券和银行共用",type:"负债类"},
{code:"2313",name:"代理兑付证券款",desc:"证券和银行共用",type:"负债类"},
{code:"2314",name:"代理业务负债",desc:"",type:"负债类"},
{code:"2401",name:"预提费用",desc:"",type:"负债类"},
{code:"2411",name:"预计负债",desc:"",type:"负债类"},
{code:"2501",name:"递延收益",desc:"",type:"负债类"},
{code:"2601",name:"长期借款",desc:"",type:"负债类"},
{code:"2602",name:"长期债券",desc:"",type:"负债类"},
{code:"2701",name:"未到期责任准备金",desc:"保险专用",type:"负债类"},
{code:"2702",name:"保险责任准备金",desc:"保险专用",type:"负债类"},
{code:"2711",name:"保户储金",desc:"保险专用",type:"负债类"},
{code:"2721",name:"独立账户负债",desc:"保险专用",type:"负债类"},
{code:"2801",name:"长期应付款",desc:"",type:"负债类"},
{code:"2802",name:"未确认融资费用",desc:"",type:"负债类"},
{code:"2811",name:"专项应付款",desc:"",type:"负债类"},
{code:"2901",name:"递延所得税负债",desc:"",type:"负债类"},
{code:"3001",name:"清算资金往来",desc:"银行专用",type:"共同类"},
{code:"3002",name:"外汇买卖",desc:"金融共用",type:"共同类"},
{code:"3101",name:"衍生工具",desc:"",type:"共同类"},
{code:"3201",name:"套期工具",desc:"",type:"共同类"},
{code:"3202",name:"被套期项目",desc:"",type:"共同类"},
{code:"4001",name:"实收资本",desc:"",type:"权益类"},
{code:"4002",name:"资本公积",desc:"",type:"权益类"},
{code:"4101",name:"盈余公积",desc:"",type:"权益类"},
{code:"4102",name:"一般风险准备",desc:"金融共用",type:"权益类"},
{code:"4103",name:"本年利润",desc:"",type:"权益类"},
{code:"4104",name:"利润分配",desc:"",type:"权益类"},
{code:"4201",name:"库存股",desc:"",type:"权益类"},
{code:"5001",name:"生产成本",desc:"",type:"成本类"},
{code:"5101",name:"制造费用",desc:"",type:"成本类"},
{code:"5201",name:"劳务成本",desc:"",type:"成本类"},
{code:"5301",name:"研发支出",desc:"",type:"成本类"},
{code:"5401",name:"工程施工",desc:"建造承包商专用",type:"成本类"},
{code:"5402",name:"工程结算",desc:"建造承包商专用",type:"成本类"},
{code:"5403",name:"机械作业",desc:"建造承包商专用",type:"成本类"},
{code:"6001",name:"主营业务收入",desc:"",type:"收入类"},
{code:"6011",name:"利息收入",desc:"金融共用",type:"收入类"},
{code:"6021",name:"手续费收入",desc:"金融共用",type:"收入类"},
{code:"6031",name:"保费收入",desc:"保险专用",type:"收入类"},
{code:"6032",name:"分保费收入",desc:"保险专用",type:"收入类"},
{code:"6041",name:"租赁收入",desc:"租赁专用",type:"收入类"},
{code:"6051",name:"其他业务收入",desc:"",type:"收入类"},
{code:"6061",name:"汇兑损益",desc:"金融专用",type:"收入类"},
{code:"6101",name:"公允价值变动损益",desc:"",type:"收入类"},
{code:"6111",name:"投资收益",desc:"",type:"收入类"},
{code:"6201",name:"摊回保险责任准备金",desc:"保险专用",type:"收入类"},
{code:"6202",name:"摊回赔付支出",desc:"保险专用",type:"收入类"},
{code:"6203",name:"摊回分保费用",desc:"保险专用",type:"收入类"},
{code:"6301",name:"营业外收入",desc:"",type:"收入类"},
{code:"6401",name:"主营业务成本",desc:"",type:"成本类"},
{code:"6402",name:"其他业务成本",desc:"",type:"成本类"},
{code:"6405",name:"营业税金及附加",desc:"",type:"成本类"},
{code:"6411",name:"利息支出",desc:"金融共用",type:"成本类"},
{code:"6421",name:"手续费支出",desc:"金融共用",type:"成本类"},
{code:"6501",name:"提取未到期责任准备金",desc:"保险专用",type:"成本类"},
{code:"6502",name:"撮保险责任准备金",desc:"保险专用",type:"成本类"},
{code:"6511",name:"赔付支出",desc:"保险专用",type:"成本类"},
{code:"6521",name:"保户红利支出",desc:"保险专用",type:"成本类"},
{code:"6531",name:"退保金",desc:"保险专用",type:"成本类"},
{code:"6541",name:"分出保费",desc:"保险专用",type:"成本类"},
{code:"6542",name:"分保费用",desc:"保险专用",type:"成本类"},
{code:"6601",name:"销售费用",desc:"",type:"成本类"},
{code:"6602",name:"管理费用",desc:"",type:"成本类"},
{code:"6603",name:"财务费用",desc:"",type:"成本类"},
{code:"6604",name:"勘探费用",desc:"",type:"成本类"},
{code:"6701",name:"资产减值损失",desc:"",type:"成本类"},
{code:"6711",name:"营业外支出",desc:"",type:"成本类"},
{code:"6801",name:"所得税",desc:"",type:"成本类"},
{code:"6901",name:"以前年度损益调整",desc:"",type:"成本类"}
]


const getUniformedCategoryRules = () => {

  const topmost = new Rule({patt: '*'});

  const entries = uniformedCategories.filter(({name}) => name !== '未识别科目');

  const toRuleDesc = (name, upperCate) => ({
    patt:name,
    cast:'=',
    prop: 'curr.name',
    action: 'CONS_SUCC',
    dest: upperCate ?? name,
    attr:{}
  })

  for (let {name, upperCate} of entries) {
    new Rule(toRuleDesc(name, upperCate)).move(topmost);
  }
  
  new Rule({cast: '*', action: 'CONS', dest: '未识别科目', attr:{}}).move(topmost)
  
  return topmost;
}

const getUniformedCategoryTable = () => {

  const replaced = uniformedCategories.filter(({upperCate, name}) => {
    return upperCate === undefined || upperCate === name
  })

  const topmost = new Category({code: '', name: '*'});

  for (let {code, name, desc, type} of replaced) {
    const cate = new Category({code, name});
    cate.attr = {desc, type};
    cate.move(topmost);
  }

  return topmost;
}
export default {getUniformedCategoryTable, getUniformedCategoryRules};